import requests
session = requests.Session()
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
}
def login(code):
    # url_user = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=202071101133'
    data = {
        'email': '15729029767',
        'icode': code,
        'origURL': 'http://www.renren.com/home',
        'domain': 'renren.com',
        'key_id': '1',
        'captcha_type': 'web_login',
        'password': '535b2be34ba6a9ba8a92af2addb740910b072b02d928d9b65b34f60cde75cfe2',
        'rkey': '39d54fe46933d48beac7ccb703ccc16a',
        'f': 'http%3A%2F%2Fwww.renren.com%2F974880655'
    }
    response = session.post(url=url_user,data=data,headers=headers)
    print(response.status_code)
    datial_page = response.text
    headers_login = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',
        #'Cookie': 'anonymid = kdl32cv8 - dwzcy8;depovince = GW;_r01_ = 1;taihe_bi_sdk_uid = e5acf42631ef610a3768018ded880d62;_de = E44EC7AA3FEFF9B3FEA45CBF925805E1;ln_uact = 15729029767;ln_hurl = http: // head.xiaonei.com / photos / 0 / 0 / men_main.gif;JSESSIONID = abcmPKEUTvBqa4AlEnxpx;taihe_bi_sdk_session = 2b0c48d7264439449e027a2312a2fbd0;ick_login = 3fd51df4 - c46c - 4e9a - 9253 - dabc6888bfa3;jebecookies = c5d13d43 - a74c - 415e - b9ab - 055afb181db3 | | | | |;p = f531926e0cb22a16a552565695a000c55;first_login_flag = 1;t = 89597085ad96ef53c69082dae89a75b65;societyguester = 89597085ad96ef53c69082dae89a75b65;id = 974880655;xnsid = 28c62e25;ver = 7.0;loginfrom = null'
    }
    url_login = 'http://www.renren.com/974880655/profile'
    datial_page_text = session.get(url=url_login,headers=headers_login).text
    # print(datial_page_text)
    with open('./renrn.html','w',encoding='utf-8') as f:
        f.write(datial_page_text)
login('TDDU')
